package org.basis.algorithm.tree;

import org.basis.algorithm.tree.common.Node;

/**
 * 递归遍历树
 *
 * @author Mr_wenpan@163.com 2021/12/22 10:10
 */
public class RecursiveTraversal {

    public static void main(String[] args) {

    }

    /**
     * 先序遍历
     */
    public static void preOrder(Node head) {
        if (head == null) {
            return;
        }
        System.out.print(head.data + "   ");
        preOrder(head.left);
        preOrder(head.right);
    }

    /**
     * 中序遍历
     */
    public static void inOrder(Node head) {
        if (head == null) {
            return;
        }
        inOrder(head.left);
        System.out.print(head.data + "   ");
        inOrder(head.right);
    }

    /**
     * 后序遍历
     */
    public static void postOrder(Node head) {
        if (head == null) {
            return;
        }
        postOrder(head.left);
        postOrder(head.right);
        System.out.print(head.data + "   ");
    }

}
